package com.teamwork.module01.controller;


import com.teamwork.common.entity.module01.Academy;
import com.teamwork.common.result.MyPage;
import com.teamwork.common.result.Result;
import com.teamwork.module01.service.AcademyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/mod01/academy")
@Slf4j
public class AcademyController {
    @Resource
    private AcademyService academyService;

    @GetMapping("/getbyname")
    public Result getAcdemyByName(String name){

        return academyService.getAcdemyByName(name);
    }

    @GetMapping("/page")
    public Result page(Integer page, Integer size){
        return academyService.getPage(page,size);
    }
    @PostMapping
    public Result addAcademy(@RequestBody Academy academy){
        return academyService.InsertOrUpdate(academy);
    }

    @DeleteMapping
    private Result delteAcademy(@RequestBody Map<String,Integer[]> map){
        Integer[] ids = map.get("ids");
        List<Integer> idlist = Arrays.asList(ids);


        return academyService.batchDelete(idlist);
    }

}
